import * as fs from 'fs';
import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  UploadedFile,
  UseInterceptors,
} from '@nestjs/common';
import { FileInterceptor } from '@nestjs/platform-express';
import { XiaohongshuService } from './xiaohongshu.service';
import { CreateXiaohongshuDto } from './dto/create-xiaohongshu.dto';
import { UpdateXiaohongshuDto } from './dto/update-xiaohongshu.dto';

@Controller('xiaohongshu')
export class XiaohongshuController {
  constructor(private readonly xiaohongshuService: XiaohongshuService) {}

  // 抓取小红书数据
  @Post('/startCrawler')
  startCrawler(@Body() data) {
    return this.xiaohongshuService.startCrawler(data.url);
  }

  // 上传
  @Post('/uploadImg')
  @UseInterceptors(FileInterceptor('file'))
  uploadImg(@UploadedFile() file, @Body() body) {
    return this.xiaohongshuService.uploadImgWidthLocal(file, body.name);
  }

  // 发布小红书
  @Post('/pubLish')
  pubLish(@Body() data) {
    return this.xiaohongshuService.pubLish(data.list);
  }

  // 发布小红书
  @Post('/chatWithAi')
  chatWithAi(@Body() data) {
    return this.xiaohongshuService.chatWithAi(data.content);
  }
}
